/***************************
统计分析-领导审核
* */
<template>
  <basic-container>
    <div class="boxsty zhiBiao" v-if="zhiShow == 1">
      <el-row>
        <assessMentHead :sign="{ a: true, b: false, c: false,d: false,e: false}" ></assessMentHead>
      </el-row>
      <el-row style="margin:25px 0 0 0 ;">

        <div :height="searchheight">
        <span style="float:right;margin-top: -30px;cursor: pointer;" @click="searchchangeadvanced">
          {{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
          <i
            :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
          />
        </span>
          <div v-show="searchadvanced">
            <el-form :inline="true" :model="searchForm" class="form-inline">

              <el-form-item label="统计名称">
                <!-- <el-input v-model="searchForm.tjmc" placeholder="统计名称" :clearable="true"></el-input>-->
                <selectSearchLeader @getDataByTjmc="getDataByTjmc"></selectSearchLeader>
              </el-form-item>


              <el-form-item>
                <el-button
                  icon="el-icon-search"
                  type="primary"
                  class="marginLeft"
                  @click="getDataList(1)"
                >检索</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </el-row>
      <el-row>
        <div style="height: 50px; border-bottom: 1px solid #b0bde2">
          <!--<el-tooltip
            class="item"
            effect="dark"
            :content="contentName"
            placement="top"
          >
            <el-button
              icon="el-icon-plus"
              type="primary"
              circle
              @click="addOrEdit()"
            ></el-button>
          </el-tooltip>-->

          <div class="pull-right">
            <el-button plain type="primary"  @click="ldsh">领导审核</el-button>
           <!-- <el-button type="primary" @click="agreeOrNot(0)" :disabled="isAgreeOrNot">同意</el-button>
            <el-button type="primary" @click="agreeOrNot(1)" :disabled="isAgreeOrNot">驳回</el-button>-->


          </div>
        </div>

      </el-row>
      <el-row>
        <el-table
          style="width: 100%;margin-top:20px"
          :data="dataList"
          border
          stripe
          ref="tableRef"
          header-align="center"
          v-if="rednermsg"
          v-loading="dataListLoading"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column type="index" :index="indexMethod"  header-align="center" align="center" label="序号" width="55"></el-table-column>
          <el-table-column prop="hzzqmc" align="center" label="统计名称" show-overflow-tooltip >
            <template slot-scope="scope">
                <span
                  @click="addOrEdit(scope.row)"
                  style="color:rgb(14, 37, 140);cursor:pointer"
                >{{scope.row.hzzqmc}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="bz" align="center" label="备注" show-overflow-tooltip></el-table-column>
          <el-table-column prop="createTime" align="center" min-width="120" label="创建时间"  show-overflow-tooltip></el-table-column>
          <el-table-column prop="state" align="center" min-width="100" label="状态"  show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.state |transState}}</span>
            </template>

          </el-table-column>
          <el-table-column align="center" width="240" fixed="right" label="操作">

            <template slot-scope="scope">
              <el-button
                type="primary"
                plain
                size="small"
                @click="scoreAuditing(scope.row)"
              >汇总查看</el-button>

            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          ></el-pagination>
        </div>

      </el-row>

    </div>

    <!-- 评分等级" -->
    <scoreLe
      @refreshDataList="getDataList()"
      v-if="zhiShow == 3"
      v-on:fnBackOldPage="fnBackOldPage"
      ref="level"
      @closeDialog="closeDialog"
    />
    <customDialog :customDialogData="customDialogData" @customDialogChildren="customDialogChildren"></customDialog>
  </basic-container>
</template>

<script>
    import assessMentHead from "@/views/statisticsanalysis/components/assessMentHead"; //转态头
    import selectSearchLeader from "@/views/statisticsanalysis/components/selectSearchLeader";
    import scoreLe from "./scoreLe"; //组件
    import customDialog from "./customDialog";
    // 接口 api
    import {
        pfhzbmhzList2,
        isAllScore,
        deptLeaderSubmit
    } from "@/api/statisticsanalysis/pfhzbmhzApi.js";
    import {
        leaderPagez,
        submitZyhz
    } from "@/api/statisticsanalysis/leaderApi.js";
    export default {
        data() {
            return {
                isAgreeOrNot: true,
                addVisible: false, //新增or编辑弹窗显隐
                shzVisible: false,
                searchheight: "0", //搜索组件的高度
                searchadvanced: true, //搜索的显隐
                contentName : '新增',
                searchForm: {}, //查询表单
                multipleSelection: [], //表格中被选中的数据
                dataList: [],
                dataListLoading: false,
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                rednermsg: true,
                zhiShow: "1",
                customDialogData: {},
            }
        },
        filters: {
            transState(val) {
                switch (val) {
                    case '0':
                        return "已创建";
                        break;
                    case '1':
                        return "分管领导审";
                        break;
                    case '2':
                        return "评分专员汇总";
                        break;
                    case '3':
                        return "领导审核";
                        break;
                    case '4':
                        return "汇总完成";
                        break;
                    case '5':
                        return "分管领导驳回";
                        break;

                }
            }
        },
        components: {
            assessMentHead, //状态头
            selectSearchLeader,//下拉选搜索组件
            scoreLe,
            customDialog
        },
        watch: {
            multipleSelection: {
                handler(val) {
                    if (val.length == 0) {
                        this.isAgreeOrNot = true;
                    } else {
                        this.isAgreeOrNot = false;
                    }
                }
            }
        },
        created() {
            this.getDataList();

        },
        methods: {
            //选择统计名称执行搜索功能
            getDataByTjmc(tjmc){
                this.searchForm.hzzqmc = tjmc ;
                this.getDataList() ;
            },
            customDialogChildren(data) {
                this.getDataList();
            },
            // 同意or驳回
            agreeOrNot(type) {
                var rows = this.$refs.tableRef.selection;
                if (rows.length == 0) {
                    rows = this.$refs.tableRef.data;
                }
                this.$confirm(`是否${type == 0 ? "同意" : "驳回"}选中数据`, "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(result => {
                        console.log("同意or驳回");
                        //提交
                        if (type == 0) {
                            var params = {
                                rows: rows,
                                type: 0
                            };
                            submitZyhz(params)
                                .then(res => {
                                    this.$message.closeAll();
                                    this.$message({
                                        type: "success",
                                        message: "提交成功!"
                                    });
                                    this.getDataList();
                                })
                                .catch(() => {
                                    this.$message({
                                        type: "error",
                                        message: "提交失败!"
                                    });
                                    this.getDataList();
                                });
                        }
                        //驳回
                        if (type == 1) {
                            var params = {
                                rows: rows,
                                type: 1
                            };
                            submitZyhz(params)
                                .then(res => {
                                    this.$message({
                                        type: "success",
                                        message: "驳回成功!"
                                    });
                                    this.getDataList();
                                })
                                .catch(() => {
                                    this.$message({
                                        type: "error",
                                        message: "提交失败!"
                                    });
                                    this.getDataList();
                                });
                        }
                    })
                    .catch(err => {
                        this.$message({
                            type: "info",
                            message: "已取消"
                        });
                    });
            },
            // 查询条件的展开关闭
            searchchangeadvanced() {
                this.searchadvanced = !this.searchadvanced;
                if (this.searchadvanced) {
                    this.searchheight = "auto";
                }
            },
            // 勾选数据
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            async scoreAuditing(data){
                const  scoreFalg = await  isAllScore(data.id) .then(res => {return res.data.data});
                console.log(scoreFalg)
                if(scoreFalg){
                    this.zhiShow = 3;
                    if (data) {
                        this.$nextTick(() => {
                            this.$refs.level.init(data);
                        });
                    }
                }else{
                    this.$message.warning("所有综合得分不为空");
                    return false;
                }
            },
            download(){},
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val
                this.pageIndex = 1
                this.getDataList()
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val
                this.getDataList()
            },
            ldsh() {
                const rows = this.$refs.tableRef.selection;
                if (rows.length == 0) {
                    this.$message.closeAll();
                    this.$message({
                        type: "info",
                        message: "请至少选择一条数据提交!"
                    });
                    return false;
                } else {
                    let ids = this.multipleSelection.map(it => {
                        return it.id;
                    });

                    this.chooseVisible = false;
                    this.customDialogData = {
                        dialogVisible: true,
                        type: 2,
                        iszbsh: 1,
                        rows: this.$refs.tableRef.selection,
                        menuType: "zbnd"
                    };
                }
            },
            // 获取数据列表
            getDataList() {
                this.dataListLoading = true;

                leaderPagez(
                    Object.assign(
                        {
                            current: this.pageIndex, //当前页
                            size: this.pageSize, // 每页条数
                        },
                        this.searchForm,
                    ),
                    2
                )
                    .then(response => {
                        this.dataList = response.data.data.records;
                        this.totalPage = response.data.data.total;
                        this.dataListLoading = false;
                    })
                    .catch(() => {
                        this.dataListLoading = false;
                    });
            },
            //子集信息
            fnBackOldPage(data) {
                if (data == "返回原页面") {
                    this.zhiShow = 1;
                    this.getDataList();
                }
            },
            indexMethod(index) { //修改table表索引

                return (this.pageIndex-1)*this.pageSize+index+1;
            },
            // 关闭新增or编辑弹窗
            closeDialog() {
                this.addVisible = false;
                this.getDataList();
            }
        }
    }
</script>

<style scoped>

</style>
